public class Twofen {
    public static void main(String[] args) {
        //二分法查照元素
        int[] arr = new int[]{1, 2, 4, 6, 7, 9, 10, 29, 30, 34, 56};
        int key =6;
        int start = 0;
        int  end = arr.length - 1;
        int  mid = (start + end) / 2;
        while (start <= end){
            if (arr[mid] == key){
                System.out.println(mid);
                break;
            }else if(arr[mid] > key) {
                end = mid - 1;
            }else {
                start = mid + 1;
            }
            mid = (end + start) / 2;
        }
        if (start > end){
            System.out.println(-1);
        }
    }
}
